package com.orangecy.flowengine.flow;


import lombok.Getter;

import java.util.*;
import java.util.stream.Collectors;

/**
 * @Author : orangeCy.奕
 * @Time : 2021/9/12
 * @desc : 猎豹养成产品源码
 * 阶段流
 */
public enum  FlowPhaseEnum {
    /**
     * 参数校验组件
     */
    PARAMS_VALIDATOR(1,"paramsValidators"),
    /**
     * 业务装配组件
     */
    BIZ_ASSEMBLY(2,"bizAssemble"),
    /**
     * 业务校验组件
     */
    BIZ_VALIDATOR(3,"bizValidators"),
    /**
     * 业务前置处理器组件
     */
    BIZ_PRE(4,"bizPres"),
    /**
     * 业务执行器组件
     */
    BIZ_EXEC(5,"bizExecs"),
    /**
     * 业务后置处理器组件
     */
    BIZ_POST(6, "bizPosts"),
    /**
     * 结果装配组件
     */
    RESULT_ASSEMBLY(7,"resultAssemble");

    @Getter
    private Integer step;
    @Getter
    private String name;

    FlowPhaseEnum(Integer step,String name) {
        this.step = step;
        this.name = name;
    }

    /**
     * 按照指定order访问顺序 key:顺序先后
     */
    private static Map<Integer, FlowPhaseEnum> flowMap = new HashMap<>();
    static {
        for(FlowPhaseEnum flowPhaseEnum : FlowPhaseEnum.values()) {
            flowMap.put(flowPhaseEnum.getStep(),flowPhaseEnum);
        }
    }

    public static List<FlowPhaseEnum> getFlowPhasesOrder() {
        return Arrays.stream(FlowPhaseEnum.values())
                .sorted(Comparator.comparing(FlowPhaseEnum::getStep))
                .collect(Collectors.toList());
    }

}